<?php
class Exts_Models_Roles extends Exts_Db_Table_Abstract
{
    protected $_name = 'acl_roles';
    protected $_primary = 'id';


    public function save( $name )
    {
        $row = $this->fetchRow( $this->select()->where('name =? ', $name ));
        if( count($row )) {
            return $row->id;
        }

        $row = $this->createRow();
        $row->name = $name;
        $row->save();
        return $row->id;

    }

    /**
     *  Busca todos los roles y devuelve un listada por key = id, value = name
     *  @return mixed bind
     */
    public function getAllToArray()
    {
        $rowset = $this->fetchAll();
        $bind = array();
        foreach( $rowset as $row ) {
            $bind[$row->id] = $row->name;
        }

        return $bind;

    }
}
